#!/usr/bin/env perl

# Translate the vlan2.py format into the wrekagrid one

# For the wrekagrid project,
# Basile Clout, October 2007


my $seed = 1;
my $cpu = 700;
my $bpout = 100;
my $bpin = 100;
my $lat = 0;
my $user = basil;
my $mem = 500000;

my $mode;
my ($line, @parts, @options, $cnt);
my ($who, $rest);
my (%cluster, %node, %network, %relation);
my $incluster;

while (my $line = <STDIN>) {

  chomp $line;

  next if ($line =~ /^#/);	# Comment line

  if ($line =~ /^s*$/){		# Empty line
    $incluster="";
    next;
  }

  if ($line =~ /^\@topo$/){
    $mode="topo";
    next;
  }elsif ($line =~ /^\@network$/){
    $mode="network";
    next;
  }elsif ($line =~ /^\@cpu$/){
    $mode="cpu";
    next;
  }

  ($who, $rest) = split /\s*:\s*/, $line;
 
  if ($mode eq "topo"){

    @options = split /\s*,\s*/, $rest;

    if ($incluster eq ""){
      $incluster = $who;
      print "incluster = $incluster\n";
      $cluster{$incluster}=[[], [@options]];
      $cnt++;
    }else{
      push @{$cluster{$incluster}[0]}, $who;
      $node{$who}=[[shift @options, $incluster], [@options] ];
    }
  }
  elsif ($mode eq "network"){
    @options = $rest.split('\s+');
    if ($who !~ /\d+<->\d+/){
      $network{$who}=[@options]; 
    }else{
      $relation{$who}=[@options];
    }
  }

}
while (my ($key, $value) = each %cluster){
  print "$key => $value->[0][0], $value->[1][0]\n";
}





